package com.tanhua.server.controller;

import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.RecommendUserDto;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TodayBestService;
import com.tanhua.server.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TodayBestService todayBestService;


    /**
     * 今日佳人：
     *    /todayBest  Get
     *    返回值 TodayBest
     */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest vo = todayBestService.todayBest();
        return ResponseEntity.ok(vo);
    }

    /**
     * 查询推荐的用户列表
     *  GET    /tanhua/recommendation
     *  请求参数：RecommendUserDto
     *  返回值：
     *     PageResult<TodayBest>
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto dto) {
        PageResult result = todayBestService.recommendation(dto);
        return ResponseEntity.ok(result);
    }

    /**
     * 佳人详情
     *  GET  /:id/personalInfo
     *  参数：查看的用户id
     *  返回值：todayBest
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId) {
        TodayBest vo = todayBestService.personalInfo(userId);
        return ResponseEntity.ok(vo);
    }

    /**
     * 查看陌生人问题
     *  get  strangerQuestions
     *  请求参数：userId(目标用户的用户id)
     *  返回值：String（目标用户设置的陌生人问题）
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId) {
        String question = todayBestService.strangerQuestions(userId);
        return ResponseEntity.ok(question);
    }

    /**
     * 回复陌生人问题（发起好友申请）
     *    POST/tanhua/strangerQuestions
     *    请求参数：
     *      userId,reply
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity relayStrangerQuestions(@RequestBody Map map) {
        //对方的用户id
        Long userId = Long.valueOf(map.get("userId").toString());
        String reply =  (String) map.get("reply");
        todayBestService.relayStrangerQuestions(userId,reply);
        return ResponseEntity.ok(null);
    }

    /**
     * 搜附近
     *  get /tanhua/search
     *  参数： gender,distance (米)
     *  返回 nearvo的list集合
     */
    @GetMapping("/search")
    public ResponseEntity search(String gender,String distance) {
        List<NearUserVo> vos = todayBestService.searchNear(gender,distance);
        return ResponseEntity.ok(vos);
    }

    /*
    * 左滑右滑
    * GET/tanhua/cards
    * */
    @GetMapping("/cards")
    public ResponseEntity cards(){
        List<TodayBest> list = todayBestService.cards();
        return ResponseEntity.ok(list);
    }
    /*
    * 喜欢
    *   GET/tanhua/:id/love
    *   喜欢右滑
    * */
    @GetMapping("{id}/love")
    public ResponseEntity love(@PathVariable("id") Long id){
        todayBestService.love(id);
        return ResponseEntity.ok(null);
    }
    /*
    * 不喜欢
    *   GET/tanhua/:id/unlove
    *   不喜欢左滑
    * */
    @GetMapping("{id}/unlove")
    public ResponseEntity unLove(@PathVariable("id") Long id){
        todayBestService.unLove(id);
        return ResponseEntity.ok(null);
    }

}
